<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var canCross = function (stones) {

      let dp = [];
      dp[0] = new Set();
      dp[0].add(0);
      for (let i = 0; i < stones.length; i++) {
        let set = dp[i];
        if (!set) break;
        for (let v of set) {
          for (let j = i + 1; j < stones.length; j++) {
            let det = stones[j] - stones[i];
            if (det >= v - 1 && det <= v + 1) {
              let set = dp[j];
              if (!set) set = new Set();
              set.add(det);
              dp[j] = set;
            }
          }
        }
      }

      return dp[stones.length - 1] != null;

    };
    console.log(canCross([0, 1, 3, 5, 6, 8, 12, 17]))
  </script>
</body>

</html>